package easy;

public class Solution_482 {
    public String licenseKeyFormatting(String s, int k) {
        char[] chars = s.toCharArray();
        StringBuffer buffer = new StringBuffer();
        for (int i = chars.length-1, count = 0; i >=0; i--) {
            char c = chars[i];
            if (c == '-') {
                continue;
            }
            if (count==k) {
                buffer.append("-");
                count = 0;
            }
            if (c >= 97 && c < 122) {
                c = (char) (c - 32);
            }
            buffer.append(Character.toUpperCase(c));
            count++;
        }
        return buffer.reverse().toString();
    }

    public static void main(String[] args) {
        Solution_482 model = new Solution_482();
        System.out.println(model.licenseKeyFormatting("5F3Z-2e-9-w", 4));
        System.out.println(model.licenseKeyFormatting("5F3Z-2e-9-w", 3));
        System.out.println(model.licenseKeyFormatting("2-5g-3-J", 2));
        System.out.println(model.licenseKeyFormatting("--a-a-a-a--", 2));
        System.out.println('a' - 0);
        System.out.println('z' - 0);
        System.out.println('Z' - 0);
    }
}
